package com.jx.web;

import com.jx.common.Result;
import com.jx.dto.AttrDto;
import com.jx.dto.GoodDto;
import com.jx.pojo.Attr;
import com.jx.pojo.Good;
import com.jx.pojo.ParamObj;
import com.jx.pojo.Trademark;
import com.jx.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 获取属性列表
     * @return
     */
    @GetMapping("/getAttrList")
    public Result<AttrDto> getAttrList() {
        Result<AttrDto> res = new Result<>();
        List<AttrDto> attrDtoList = searchService.getAttrList();
        res.setCode(200);
        res.setMessage("成功");
        res.setData(attrDtoList);
        return res;
    }


    /**
     * 获取品牌列表
     * @return
     */
    @GetMapping("/getTrademarkList")
    public Result<Trademark> getTrademarkList() {
        Result<Trademark> res = new Result<>();
        List<Trademark> trademarkList = searchService.getTrademarkList();
        res.setCode(200);
        res.setMessage("成功");
        res.setData(trademarkList);
        return res;
    }

    /**
     * 获取商品列表
     * @return
     */
    @PostMapping("/getGoodList")
    public Result<GoodDto> getGoodsList(@RequestBody ParamObj paramObj) {
        System.out.println(paramObj);
        Result<GoodDto> res = new Result<>();
        GoodDto goodDto = searchService.getGoodsListByConditionAndPage(paramObj);
        res.setCode(200);
        res.setMessage("成功");
        res.setData(Arrays.asList(goodDto));
        return res;
    }

}
